package com.dao.impl;

import com.dao.EmployeeDao;
import entity.EmpEntity;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionFactoryUtil;

import java.util.List;

public class EmployeeDaoImpl implements EmployeeDao {
    // 第一种分页方法（内存分页）
    @Override
    public List<EmpEntity> getAllByRowBound(RowBounds rowBounds) {
        return null;
    }

    // 第二种分页方法（pageHelper 插件物理分页）
    @Override
    public List<EmpEntity> getAllByPageHelper(int pageNum, int pageSize) {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            EmployeeDao mapper = sqlSession.getMapper(EmployeeDao.class);
            List<EmpEntity> list = mapper.getAllByPageHelper(pageNum, pageSize);
            return list;
        }
    }

    // 自定义分页
    @Override
    public List<EmpEntity> getAllByCustom(int offset, int limit) {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            EmployeeDao mapper = sqlSession.getMapper(EmployeeDao.class);
            List<EmpEntity> list = mapper.getAllByCustom(offset, limit);
            return list;
        }
    }

    // 分页加数字
    @Override
    public int getCountByCustom() {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            EmployeeDao mapper = sqlSession.getMapper(EmployeeDao.class);
            int recordCount = mapper.getCountByCustom();
            return recordCount;
        }
    }
}
